/**
 * Copyright (c) subnew
 * Licensed under the GPL;
 * @email:joseanluo@gmail.com
 * @Title: EntityManager.java
 * @Package com.subnew.copyman.frame.dao
 */
package com.subnew.mango.frame.dao;

import java.io.Serializable;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.subnew.mango.frame.exception.DaoException;


/**
 * DAO层基层抽象类。<br>
 * 子类需重载getDao()函数提供该DAO.<br>
 * 需要日志slf4j支持。
 * @param <T>
 *            领域对象类型
 * @param <PK>
 *            领域对象的主键类型
 *          <p>  eg. public class UserManager extends EntityManager&lt;User, Long>{ }</p>
 * @author JoseanLuo
 * @date 2014年9月1日 上午11:16:09
 * @version V1.0
 */
public abstract class EntityManager<T,PK extends Serializable>  implements DAO<T, PK> {
	/**
	 * 日志对象
	 */
	protected Logger logger = LoggerFactory.getLogger(getClass());
	/**
	* 取得实例DAO
	* @return  
	* @Title: getDAO
	* @author JoseanLuo  
	* @date 2014年9月9日 下午8:58:29
	* @version V1.0
	 */
	protected abstract DAO<T, PK> getDAO();
	
	
	/* (non-Javadoc)
	 * @see com.subnew.copyman.frame.dao.DAO#save(java.lang.Object)
	 */
	@Override
	public Serializable save(T entity) throws DaoException {
		return getDAO().save(entity);
	}
	
	/* (non-Javadoc)
	 * @see com.subnew.copyman.frame.dao.DAO#update(java.lang.Object)
	 */
	@Override
	public void update(T entity) throws DaoException {
		getDAO().update(entity);
	}
	
	/* (non-Javadoc)
	 * @see com.subnew.copyman.frame.dao.DAO#findByPk(java.io.Serializable)
	 */
	@Override
	public T findByPk(PK pk) throws DaoException {
		return getDAO().findByPk(pk);
	}
	
	/* (non-Javadoc)
	 * @see com.subnew.copyman.frame.dao.DAO#delete(java.io.Serializable)
	 */
	@Override
	public void delete(PK pk) throws DaoException {
      getDAO().delete(pk);
	}
	
    /* (non-Javadoc)
     * @see com.subnew.copyman.frame.dao.DAO#deleteByPks(java.util.List)
     */
    @Override
    public void deleteByPks(List<PK> pks) throws DaoException {
       getDAO().deleteByPks(pks);    	
    }
}
